package cx.mybatis.session.defaults;

import cx.mybatis.session.Configuration;
import cx.mybatis.session.SqlSession;
import cx.mybatis.session.SqlSessionFactory;

/**
 * 默认的SqlSession工厂
 * 可以打开(获取)一个默认的SqlSession
 * @Author:cxy
 * @Date:2022/4/9 12:17
 */
public class DefaultSqlSessionFactory implements SqlSessionFactory {

    private final Configuration configuration;

    public DefaultSqlSessionFactory(Configuration config) {
        this.configuration = config;
    }

    /**
     * 打开一个session
     * 其中mapperRegistry中已经缓存了mapper工厂
     * @return
     */
    @Override
    public SqlSession openSession() {
        return new DefaultSqlSession(configuration);
    }
}
